package com.shawn.baseappbygroovydsl.ui.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;

/**
 * 描述：
 * 作者： shawn
 * 时间： 2024/5/918:26
 */
public class StrokeTextView extends androidx.appcompat.widget.AppCompatTextView {

    private int mStrokeColor;
    private float mStrokeWidth;

    private int mTextColor;

    public StrokeTextView(Context context) {
        super(context);
        init();
    }

    public StrokeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public StrokeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        mTextColor = Color.parseColor("#FD3D45");
        mStrokeColor = Color.parseColor("#0000FF"); // 描边颜色，默认为黑色
        mStrokeWidth = 12.0f; // 描边宽度
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 绘制描边效果
        getPaint().setStyle(Paint.Style.STROKE);
        getPaint().setStrokeWidth(mStrokeWidth);
        setTextColor(mStrokeColor);
        super.onDraw(canvas);

        // 绘制文字
        getPaint().setStyle(Paint.Style.FILL);
        setTextColor(mTextColor);
        super.onDraw(canvas);
    }

    public void setStrokeColor(int color) {
        mStrokeColor = color;
        invalidate();
    }

    public void setStrokeWidth(float width) {
        mStrokeWidth = width;
        invalidate();
    }

    public void setMTextColor(int mTextColor) {
        this.mTextColor = mTextColor;
    }
}